
var colorArr = [
    { "color": "#5470C6" },
    { "color": "#91CC75" },
    { "color": "#FAC858" },
    { "color": "#EE6666" },
    { "color": "#73C0DE" },
];

var colorArr2 = ['#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53', '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42']

// 用户ID
let id = getUrlParam("id");
$(function () {
    GetUserRole();
});
//获取用户权限
function GetUserRole() {
    // let thisdata = [];
    // thisdata.push(InitRole(id));
    let USERdata = InitRole(id);
    if (USERdata != null) {
        choose('year');
        InitChart();
        InitData();
    }
    else OpenErrmsg("../../web/errhtml/404.html");
}

function choose(type) {
    $('#lab_1').removeClass("labelstyleChoose labelstyle");
    $('#lab_2').removeClass("labelstyleChoose labelstyle");
    $('#lab_3').removeClass("labelstyleChoose labelstyle");

    $('#lab_1').addClass(type == "week" ? "labelstyleChoose" : "labelstyle");
    $('#lab_2').addClass(type == "month" ? "labelstyleChoose" : "labelstyle");
    $('#lab_3').addClass(type == "year" ? "labelstyleChoose" : "labelstyle");
    if (type == "week") {
        $('#db_Start').datebox('setValue', GetDateStr(-7));
        $('#db_End').datebox('setValue', getCurrDate());
    }
    if (type == "month") {
        $('#db_Start').datebox('setValue', GetDateStr(-31));
        $('#db_End').datebox('setValue', getCurrDate());
    }
    if (type == "year") {
        $('#db_Start').datebox('setValue', GetDateStr(-7));
        $('#db_End').datebox('setValue', getCurrDate());
    }
    //查询数据，刷新
    InitChart();
    InitData();
}
function InitData() {
    var data = [
        { "ID": "Plan01", "workname": "电力改造", "status": "未开始", "workplace": "一层甲板", "worktype": "冷工", "department": "电气", "begintime": "2021-09-09 09:00", "endtime": "2021-09-09 09:00" },
        { "ID": "Plan02", "workname": "空压机改造", "status": "进行中", "workplace": "一层甲板", "worktype": "进入限制空间", "department": "机械", "begintime": "2021-09-09 09:00", "endtime": "2021-09-09 09:00" },
        { "ID": "Plan03", "workname": "勘探测试", "status": "未开始", "workplace": "一层甲板", "worktype": "热工", "department": "机械", "begintime": "2021-09-09 09:00", "endtime": "2021-09-09 09:00" },
        { "ID": "Plan05", "workname": "烟探测试", "status": "已完成", "workplace": "一层甲板", "worktype": "热工", "department": "仪表", "begintime": "2021-09-09 09:00", "endtime": "2021-09-09 09:00" },
        { "ID": "Plan04", "workname": "电力改造", "status": "已完成", "workplace": "一层甲板", "worktype": "热工", "department": "电气", "begintime": "2021-09-09 09:00", "endtime": "2021-09-09 09:00" },
    ];
    $('#dg_DateList').datagrid({
        data: data,
        onLoadSuccess: function (data) {
            // $("#tb01").css("background-color", "white");
        }
    });

}
function InitChart() {
    let data = [
        { "name": "1月", "qty": "60" },
        { "name": "2月", "qty": "18" },
        { "name": "3月", "qty": "30" },
        { "name": "4月", "qty": "16" },
        { "name": "5月", "qty": "70" },
        { "name": "6月", "qty": "23" },
        { "name": "7月", "qty": "65" },
        { "name": "8月", "qty": "75" },
        { "name": "9月", "qty": "27" },
        { "name": "10月", "qty": "93" },
        { "name": "11月", "qty": "28" },
        { "name": "12月", "qty": "37" },
    ];

    var myChart = echarts.init(document.getElementById('chartdiv'));
    var xAxisDataLine = new Array();
    var seriesDataLine = new Array();
    for (var i = 0; i < data.length; i++) {
        var item = data[i];
        xAxisDataLine.push(item.name)
        seriesDataLine.push({
            value: item.qty,
            // itemStyle: {
            //     color: colorArr[i].color
            // }
        });
    }
    // 指定图表的配置项和数据
    var option = {
        title: {
        },
        tooltip: {},
        legend: {
        },
        xAxis: {
            data: xAxisDataLine,
            axisLine: {
                lineStyle: {
                    color: '#6782a0',
                    width: 1, //这里是为了突出显示加上的
                }
            },
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#6782a0',
                }
            }
        },
        yAxis: {
            axisLine: {
                lineStyle: {
                    color: '#6782a0',
                    width: 1, //这里是为了突出显示加上的
                }
            },
            splitLine: {
                show: true,
                lineStyle: {
                    type: 'solid',
                    color: '#f3f3f3',
                }
            },
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#6782a0'
                }
            }
        },
        series: [{
            type: 'bar',
            barWidth: '50px',
            data: seriesDataLine
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}

